package com.yigang.controller;

import java.text.ParseException;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yigang.entity.UserAddress;
import com.yigang.service.UserAddressService;
import com.yigang.utils.ResultUtil;

@Controller
@RequestMapping("/address")
public class UserAddressController {
	@Autowired
	private UserAddressService userAddressService;
	//增删改查方法
		@RequestMapping("addressList")
		public String addressList() {
			return "jsp/address/addressList";
		}
		@RequestMapping("addAddress")
		public String addAddress() {
			return "jsp/address/addAddress";
		}

		@RequestMapping("editAddress/{address_id}")
		public String editAddress(@PathVariable("address_id") int address_id, HttpSession session) {
			UserAddress address = userAddressService.selectUserAddressById(address_id);

			session.setAttribute("address", address);
			return "jsp/address/editAddress";
		}

		//添加活动关联商品
		@RequestMapping("insertAddress")
		@ResponseBody
		public ResultUtil insertAddress(UserAddress record) {
			userAddressService.insertSelective(record);
			return ResultUtil.ok();

		}

		@RequestMapping("deleteAddressById")
		@ResponseBody
		public ResultUtil deleteAddressById(int address_id) {
			
			return userAddressService.deleteByPrimaryKey(address_id);
		}

		@RequestMapping("getAddressList")
		@ResponseBody
		public ResultUtil getAddressList(Integer page, Integer limit, UserAddress record) {

			return userAddressService.selectUserAddressList(page, limit, record);
		}

		@RequestMapping("updateAddress")
		@ResponseBody
		public ResultUtil updateAddress(UserAddress record) throws ParseException {
			
			return userAddressService.updateByPrimaryKeySelective(record);
		}
}
